import axios from "axios"
import { ElMessage } from "element-plus"
// import { ElLoading } from "element-plus"

const Service = axios.create({
    timeout: 8000,
    baseURL: `http://${window.location.hostname}:8044/`,
    headers: {
        "Content-type": "multipart/form-data; boundary=---011000010111000001101001"
    }
})
// 请求拦截-增加loading，对请求做处理
// let loadingObj = null
Service.interceptors.request.use(config => {
    // loadingObj = ElLoading.service({
    //     lock: false,
    //     text: 'config',
    //     background: 'rgba(0,0,0,1)'
    // })
    return config
})
// 响应拦截-对返回值做统一处理
Service.interceptors.response.use(response => {
    // loadingObj.close()
    const data = response.data
    // if (data.meta.status != 200 && data.meta.status != 201) {
    //     ElMessage.error(data.meta.msg || "服务器错误")
    // }
    return data
}, error => {
    console.log(error)
    // loadingObj.close()
    ElMessage({
        message: "服务器错误",
        type: "error",
        duration: 2000
    })
})

// post请求
export const post = config => {
    return Service({
        ...config,
        method: "post",
        data: config.data
    })
}

// get请求
export const get = config => {
    return Service({
        ...config,
        method: "get",
        params: config.data
    })
}

// put请求
export const put = config => {
    return Service({
        ...config,
        method: "put",
        params: config.data
    })
}



export const getLine = data => {
    return get({
        url: "/getLine",
        data
    })
}

export const getPointByExtent = data => {
    return get({
        url: "/getPointByExtent",
        data
    })
}

export const getPointByWkt = data => {
    return get({
        url: "/getPointByWkt",
        data
    })
}


// export const loginApi = data => {
//     return post({
//         url: "/login",
//         data
//     })
// }

// export const AddUserApi = data => {
//     return post({
//         url: "/users",
//         data
//     })
// }



// export const ChangeStateApi = data => {
//     return put({
//         url: `users/${data.id}/state/${data.mg_state}`
//     })
// }